package com.homework.test1;

public class Demo5 {
    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int)(Math.random()*(100+1-1)) + 1;
        }
        for (int i : arr) {
            System.out.print(i+" ");
        }
        System.out.println();
        System.out.println("数组中去除最大值和最小值之后的平均值:"+avg(arr));

    }
    public static double avg(int[] arr) {
        int max = 0,min = arr[0];

        for (int i : arr) {
            if (max<i){
                max = i;
            }
            if (min>i){
                min = i;
            }
        }
        double sum = 0.0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i]==max||arr[i]==min){
                arr[i]=0;
            }
        }
        for (int i : arr) {
            System.out.print(i+" ");
        }
        for (int i : arr) {
            sum+=i;
        }
        System.out.println();
        double avg = sum/arr.length;
        return avg;
    }
}
